package org.feit.findword.game;


public class GenericBoard extends Board {
	private int mSize;
	private int mWidth;
	private int mHeight;

	private static long mTransitionsBits[];
	
	public GenericBoard(int rows, int cols, String[] b, boolean isMK) {
		super(b, isMK);
		mSize = rows * cols;
		mWidth = cols;
		mHeight = rows;
		mTransitionsBits = new long[mSize];
		generateTransitionBits();
	}

	public int getSize() {
		return mSize;
	}

	public int getWidth() {
		return mWidth;
	}
	
	public int getHeight() {
		return mHeight;
	}
	
	private void generateTransitionBits() {
		long m;
		int[] dx = {-1, 0, 1, 1, 1, 0, -1, -1};
		int[] dy = {-1, -1, -1, 0, 1, 1, 1, 0};
		//int[] dx = {-1, 0, 1, 0};
		//int[] dy = {0, 1, 0, -1}; 
		for(int i = 0; i < mHeight; i++){
			for(int j = 0; j < mWidth; j++){
				m = 0;
				for(int k = 0; k < dx.length; k++){
					int cy = i + dy[k];
					int cx = j + dx[k];
					if(cx >= 0 && cx < mWidth && cy >= 0 && cy < mHeight){
						m |= (1L << (cy * mHeight + cx));
					}
				}
				mTransitionsBits[i * mHeight + j] = m;
			}
		}
	}

	@Override
	public long transitions(int position) {
		return mTransitionsBits[position];
	}

}
